package com.test.springCloud.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.test.springcloud.pojo.DeptPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 消费者控制类
 */
@RestController
public class DeptController {

    @Autowired
    private RestTemplate restTemplate;//使用此模板调用服务

    private static final String PREFIX = "http://localhost:8072";//本项目提供的配置port

    @GetMapping("/client/dept/get")
    public String get(){
        //第一个参数是访问路径，第二个参数是返回值类型
        String forObject = restTemplate.getForObject(PREFIX + "/lxf/GetAllDept", String.class);

        return forObject;
    }

    @PostMapping("/client/dept/add")
    public ResponseEntity<Boolean> add(DeptPojo deptPojo){
        //第一个参数是访问路径，第二个参数是传入的数据，第三个参数是返回值类型
        return restTemplate.postForEntity(PREFIX+"/lxf/add/",deptPojo,Boolean.class);
    }
}
